﻿package sedie 
{
	import flash.display.MovieClip;
	import flash.events.Event;

	/**
	 * ...
	 * @author Doan Nguyen Thuy Nha Truc (Bamboo)	
	 */
	public class CardPanel extends MovieClip
	{
		public var cardArr:Array;
		public var card1:MovieClip;
		public var card2:MovieClip;
		public var card3:MovieClip;
		public var card4:MovieClip;
		public var bowl:MovieClip;
		private var dir:int = 0;
		public function CardPanel() 
		{
			cardArr = new Array(card1,card2, card3, card4);
			hideAllCards();
			bowl.addEventListener(Event.ENTER_FRAME, hdlEnterFrame);
		}
		
		private function hdlEnterFrame(e:Event):void 
		{
			if (dir == -1) {
				bowl.prevFrame();
			} else if (dir == 1) {
				bowl.nextFrame();
			}
		}
		
		
		
		/**
		 * @author Bamboo
		 * @param	cards
		 */
		public function initCards(result:String):void {
			var ranA:int = Math.random() * 4;
			var ranB:int = Math.random() * 3;
			if (ranA != ranB) {
				var temp:MovieClip = cardArr[ranA];
				cardArr[ranA] = cardArr[ranB];
				cardArr[ranB] = temp;
			}
			var num:int = parseInt(result.substr(1, 1), 10);
			
			for (var i:int = 0; i < num; i++ )
				cardArr[i].gotoAndStop("red");
			this.dir = 1;
		}
		
		/**
		 * @author Bamboo
		 */
		public function hideAllCards():void {
			this.dir = -1;
			for (var i:int = 0; i < cardArr.length; i++ )
				cardArr[i].gotoAndStop("white");
		}
		
	}

}